<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/28 0028
 * Time: 下午 5:13
 */

namespace app\admin\controller;

use app\common\model\SystemLog as SystemLogModel;
use app\common\controller\AdminBase;
use think\Request;

class SystemLog  extends AdminBase
{
    protected $system_model;

    protected function _initialize()
    {
        parent::_initialize();
        $this->system_model = new SystemLogModel();
    }

    /**
     * 用户管理
     * @param string $keyword
     * @param int    $page
     * @return mixed
     */
    public function logindex($keyword = '', $page = 1){

        $map = [];
        if ($keyword) {
            $map['operation'] = ['like', "%{$keyword}%"];
        }
        $system_list = $this->system_model->where($map)->order('id DESC')->paginate(15, false, ['page' => $page]);

        return $this->fetch('index', ['system_list' => $system_list, 'keyword' => $keyword]);

    }

    public function adminOpeaIndex(Request $request,$keyword = '', $page = 1)
    {
        $map = [];
        if ($keyword) {
            $map['car_system_log.operation|car_system_log.user_ip|car_admin_user.username'] = ['like', "%{$keyword}%"];
        }

        $star_time = $request->param('star_time');
        $end_time  = $request->param('end_time');

        if ($star_time && $end_time) {
            $map['car_system_log.create_time'] = ['between', "$star_time,$end_time"];
        }
        $system_list = $this->system_model->where($map)
            ->join('car_admin_user', 'car_admin_user.id = car_system_log.admin_user_id')
            ->field(['car_system_log.*', 'car_admin_user.username'])
            ->order('id DESC')->paginate(15, false, [
                'page' => $page,
                'query' => ['keyword' => $keyword, 'star_time' => $star_time, 'end_time' => $end_time]
            ]);

        return $this->fetch('adminopeaindex', [
            'system_list' => $system_list,
            'keyword' => $keyword,
            'star_time' => $star_time,
            'end_time' => $end_time
        ]);
    }

}